package entities;

import java.util.ArrayList;

/**
 * Entity Class for Tournament. A Tournament is a Event with a certain result.
 * 
 * @author MK
 * @see entities.Event
 * 
 */
public class Tournament extends Event {

	private int standing;

	private Tournament() {
		super();
	}

	public Tournament(Long date, Address place,
			ArrayList<Participant> participants, int standing) {
		super(date, place, participants);
		this.standing = standing;
	}

	public Tournament(Tournament tournament) {
		this(tournament.date, tournament.place, tournament.participants,
				tournament.standing);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + standing;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tournament other = (Tournament) obj;
		if (standing != other.standing)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Tournament [standing=" + standing + ", date=" + date
				+ ", participants=" + participants + ", place=" + place + "]";
	}

	public int compareTo(Tournament tournament) {

		if (super.compareTo((Event) tournament) != 0) {
			return super.compareTo((Event) tournament);
		} else {
			return this.standing - tournament.standing;
		}
	}

	public int getStanding() {
		return standing;
	}
}